<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
    <div>
	   <p>请输入1到100任意一个你猜的数：</p>
	   <input type="text" id="text1"> 
	   <input type="button" value="确定" onclick="show()">
	   <input type="text" id="text2"><br>
	   <span id="span"></span><span id="span1"></span>
	</div>
 </body>
 <script>
      var i = 1;  
	  var n = 5;
	  var s = parseInt(Math.random()*100);
	   alert(s);
      function show(){ 

		if((n - i) == -1){
		  return ;
		}

		var text1 = document.getElementById("text1").value;
		var span = document.getElementById("span");
		var span1 = document.getElementById("span1");

		 if(i == 5){
		    span.innerHTML = "你已经用完了猜数的机会;";
			span.style.color = "red";
		 } 
		if(text1 == s){
		   document.getElementById("text2").value = "聪明";  
		   document.getElementById("text2").style.color = "green";
		   span1.innerHTML = "恭喜你猜对了";
		   i++;
		   return ;
		}else if(text1 > s){
		   document.getElementById("text2").value = "猜大了";
		   document.getElementById("text2").style.color = "red";
		   if(i == 5){
		     span1.innerHTML="";
		   }else{
		     span1.innerHTML = "答错了，你还有"+(n-i)+"次猜数的机会";
		   }
		}
		else{
		   document.getElementById("text2").value = "猜小了";
		   document.getElementById("text2").style.color = "red";
		   if(i == 5){
		     span1.innerHTML="";
		   }else{
		     span1.innerHTML = "答错了，你还有"+(n-i)+"次猜数的机会";
		   }
		} 
		i ++;
	  }
 </script>
</html>
